package com.sbpm.crmbpm.client.deprecforms;

import com.sbpm.crmbpm.shared.data.TransferInfo;
import com.sencha.gxt.widget.core.client.FramedPanel;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
import com.sencha.gxt.widget.core.client.form.CheckBox;
import com.sencha.gxt.widget.core.client.form.FieldLabel;
import com.sencha.gxt.widget.core.client.form.FieldSet;
import com.sencha.gxt.widget.core.client.form.TextField;

import java.util.HashMap;
import java.util.Map;

/**
 * @deprecated
 */
public abstract class CreateTransferForm extends ProcessForm
{

    private TextField name;
    private TextField sum;
    private TextField receiver;
    private CheckBox forRework;
    private TransferInfo transfer;
    private Long id;
    private Long processInstanceId;

    public CreateTransferForm()
    {
        init( "Create transfer" );
    }

    @Override
    public Map< String, Object > getData()
    {
        Map< String, Object > data = new HashMap<>();
        /*transfer.setName( name.getValue() );
        transfer.setReceiver( receiver.getValue() );
        transfer.setSum( sum.getValue() );*/
        data.put( "transfer.name", name.getValue() );
        data.put( "transfer.sum", sum.getValue() );
        data.put( "transfer.receiver", receiver.getValue() );
        data.put( "transfer.id", id );
        data.put( "transfer.processInstanceId", processInstanceId );
        /*TaskInfo task = new TaskInfo();
        task.setName( name.getValue() );*/
        //data.put( "transfer", transfer );
//        data.put( "transfer", task );
        return data;
    }

    @Override
    public void setData( Map< String, Object > data )
    {
        /*transfer = ( TransferInfo ) data.get( "transfer" );
        if( transfer == null )
        {
            transfer = new TransferInfo();
        }*/
        name.setValue( ( String )data.get( "transfer.name" ) );
        sum.setValue( ( String )data.get( "transfer.sum" ) );
        receiver.setValue( ( String )data.get( "transfer.receiver" ) );
        id = ( Long )data.get( "transfer.id" );
        processInstanceId = ( Long )data.get( "transfer.processInstanceId" );
/*
        name.setValue( transfer.getName() );
        sum.setValue( transfer.getSum() );
        receiver.setValue( transfer.getReceiver() );
*/
        forRework.setValue( Boolean.FALSE.equals( data.get( "approvedByVerifier" ) ) );
    }

    public void createForm( FramedPanel panel )
    {


        FieldSet fieldSet = new FieldSet();
        fieldSet.setHeadingText( "Transfer information" );
        fieldSet.setCollapsible( false );
        panel.add( fieldSet );

        VerticalLayoutContainer p = new VerticalLayoutContainer();
        fieldSet.add( p );

        name = new TextField();
        name.setAllowBlank( false );
        p.add( new FieldLabel( name, "Name" ), new VerticalLayoutData( 1, -1 ) );

        sum = new TextField();
        sum.setAllowBlank( false );
        p.add( new FieldLabel( sum, "Sum" ), new VerticalLayoutData( 1, -1 ) );

        receiver = new TextField();
        receiver.setAllowBlank( false );
        p.add( new FieldLabel( receiver, "Receiver" ), new VerticalLayoutData( 1, -1 ) );

        forRework = new CheckBox();
        forRework.setBoxLabel( "For Rework" );
        forRework.setReadOnly( true );
        forRework.setEnabled( false );
        p.add( forRework, new VerticalLayoutData( 1, -1 ) );

    }


}
